<?php
// +----------------------------
// | Created by PhpStorm
// +----------------------------
// | Author: YnnSon
// +----------------------------
namespace app\api\model;

use app\api\service\Token;
use app\lib\enum\MemberLogEnum;
use app\lib\enum\OrderStatusEnum;
use app\lib\enum\PageEnum;
use app\lib\enum\PayStatusEnum;
use app\lib\enum\RefundStatusEnum;
use app\lib\enum\ZtEnum;
use app\lib\exception\CurdException;
use app\lib\exception\OrderException;
use app\lib\exception\SuccessMessage;
use think\Db;
use think\Exception;
use think\Log;

/**
 * 订单
 * Class Order
 * @package app\api\model
 */
class Order extends BaseModel
{
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    /**
     * @Desc 格式化日期
     *
     * @param $value
     *
     * @return false|string
     */
    protected function getSubscribeDateAttr($value)
    {
        return date('Y.m.d H:i', $value);
    }

    /**
     * @Desc 格式化金额
     *
     * @param $value
     *
     * @return false|string
     */
    protected function getTotalAmountAttr($value)
    {
        return (int)$value;
    }

    /**
     * @Desc 格式化日期
     *
     * @param $value
     *
     * @return false|string
     */
    protected function getCreateTimeAttr($value)
    {
        return date('Y.m.d H:i', $value);
    }

    /**
     * @Desc 格式化日期
     *
     * @param $value
     *
     * @return false|string
     */
    protected function getAddTimeAttr($value, $data)
    {
        return $data['create_time'];
    }

    /**
     * @Desc 格式化日期
     *
     * @param $value
     *
     * @return false|string
     */
    protected function getYuyueTimeAttr($value, $data)
    {
        return $data['subscribe_date'];
    }

    /**
     * @Desc 追加检车站名称字段
     *
     * @param $value
     * @param $data
     *
     * @return false|string
     */
    protected function getCompanyNameAttr($value, $data)
    {
        return Db::name('company')->where('id', '=', $data['company_id'])->value('company_name');
    }

    /**
     * @Desc 追加所有人字段
     *
     * @param $value
     * @param $data
     *
     * @return false|string
     */
    protected function getUserNameAttr($value, $data)
    {
        return Db::name('driving_license')->where('id', '=', $data['driving_license_id'])->value('user_name');
    }

    /**
     * @Desc 追加备注字段
     *
     * @param $value
     * @param $data
     *
     * @return false|string
     */
    protected function getRemarksAttr($value, $data)
    {
        return Db::name('driving_license')->where('id', '=', $data['driving_license_id'])->value('remarks');
    }

    /**
     * @Desc 追加检车站地址字段
     *
     * @param $value
     * @param $data
     *
     * @return false|string
     */
    protected function getCompanyAddrAttr($value, $data)
    {
        return Db::name('company')->where('id', '=', $data['company_id'])->value('company_addr');
    }

    /**
     * @Desc 追加检车站联系电话字段
     *
     * @param $value
     * @param $data
     *
     * @return false|string
     */
    protected function getTelephoneAttr($value, $data)
    {
        return Db::name('company')->where('id', '=', $data['company_id'])->value('telephone');
    }

    /**
     * @Desc 追加车牌号字段
     *
     * @param $value
     * @param $data
     *
     * @return false|string
     */
    protected function getLicenseNumberAttr($value, $data)
    {
        return Db::name('driving_license')->where('id', '=', $data['driving_license_id'])->value('license_number');
    }

    /**
     * @Desc 追加订单状态名称字段
     *
     * @param $value
     * @param $data
     *
     * @return string
     */
    // protected function getOrderStatusNameAttr($value, $data)
    // {
    //     $order_status_name = '';
    //     if ($data['is_invalid']) {
    //         $order_status_name = '无效订单，请联系客服';
    //     } else {
    //         switch ($data['order_status']) {
    //             case OrderStatusEnum::UNPAID:
    //                 $order_status_name = '待付款';
    //                 break;
    //             case OrderStatusEnum::PAID:
    //                 if (RefundStatusEnum::REFUND_FAILED == $data['refund_status']) {
    //                     $order_status_name = '退款失败';
    //                 } elseif (RefundStatusEnum::APPLIED == $data['refund_status']) {
    //                     $order_status_name = '已申请退款';
    //                 } else {
    //                     $order_status_name = '已付款';
    //                 }
    //                 break;
    //             case OrderStatusEnum::COMPLETED:
    //                 $order_status_name = '已完成';
    //                 break;
    //             case OrderStatusEnum::CANCELLED:
    //                 if (RefundStatusEnum::REFUNDED == $data['refund_status']) {
    //                     $order_status_name = '已退款';
    //                 } elseif (RefundStatusEnum::REFUNDING == $data['refund_status']) {
    //                     $order_status_name = '退款中';
    //                 } else {
    //                     $order_status_name = '已取消';
    //                 }
    //                 break;
    //         }
    //     }
    //     return $order_status_name;
    // }
    /**
     * @Desc 追加订单状态名称字段
     *
     * @param $value
     * @param $data
     *
     * @return string
     */
    // protected function getOrderStatusEnnameAttr($value, $data)
    // {
    //     $order_status_enname = '';
    //     if ($data['is_invalid']) {
    //         $order_status_enname = 'invalid';
    //     } else {
    //         switch ($data['order_status']) {
    //             case OrderStatusEnum::UNPAID:
    //                 $order_status_enname = 'unpaid';
    //                 break;
    //             case OrderStatusEnum::PAID:
    //                 if (RefundStatusEnum::REFUND_FAILED == $data['refund_status']) {
    //                     $order_status_enname = 'refund-failed';
    //                 } elseif (RefundStatusEnum::APPLIED == $data['refund_status']) {
    //                     $order_status_enname = 'refund-applied';
    //                 } else {
    //                     $order_status_enname = 'paid';
    //                 }
    //                 break;
    //             case OrderStatusEnum::COMPLETED:
    //                 $order_status_enname = 'completed';
    //                 break;
    //             case OrderStatusEnum::CANCELLED:
    //                 if (RefundStatusEnum::REFUNDED == $data['refund_status']) {
    //                     $order_status_enname = 'refunded';
    //                 } elseif (RefundStatusEnum::REFUNDING == $data['refund_status']) {
    //                     $order_status_enname = 'refunding';
    //                 } else {
    //                     $order_status_enname = 'cancelled';
    //                 }
    //                 break;
    //         }
    //     }
    //     return $order_status_enname;
    // }
    /**
     * @Desc 追加交管中心订单状态名称字段
     *
     * @param $value
     * @param $data
     *
     * @return string
     */
    protected function getOrderStatusNameAttr($value, $data)
    {
        $order_status_name = '';
        if ($data['is_invalid']) {
            $order_status_name = '无效订单，请联系客服';
        } elseif (null !== $data['zt']) {
            switch ($data['zt']) {
                case ZtEnum::FAILED:
                    $order_status_name = '审核未通过';
                    break;
                case ZtEnum::CANCELLED:
                    $order_status_name = '已取消';
                    break;
                case ZtEnum::WAIT_AUDIT:
                    $order_status_name = '待审核';
                    break;
                case ZtEnum::AUDITING:
                    $order_status_name = '审核中';
                    break;
                case ZtEnum::SUCCESS:
                    $order_status_name = '预约成功';
                    switch ($data['order_status']) {
                        case OrderStatusEnum::PAID:
                            if (RefundStatusEnum::REFUND_FAILED == $data['refund_status']) {
                                $order_status_name = '退款失败';
                            } elseif (RefundStatusEnum::APPLIED == $data['refund_status']) {
                                $order_status_name = '已申请退款';
                            } elseif (RefundStatusEnum::REFUNDING == $data['refund_status']) {
                                $order_status_name = '退款中';
                            } else {
                                $order_status_name = '已付款';
                            }
                            break;
                        case OrderStatusEnum::COMPLETED:
                            $order_status_name = '已完成';
                            break;
                        case OrderStatusEnum::CANCELLED:
                            if (RefundStatusEnum::REFUNDED == $data['refund_status']) {
                                $order_status_name = '已退款';
                            } else {
                                $order_status_name = '已取消';
                            }
                            break;
                    }
                    break;
                case ZtEnum::CHECKING:
                    $order_status_name = '检测中';
                    break;
                case ZtEnum::COMPLETED:
                    $order_status_name = '检测完成';
                    break;
            }
        } else {
            switch ($data['order_status']) {
                case OrderStatusEnum::UNPAID:
                    $order_status_name = '待付款';
                    break;
                case OrderStatusEnum::PAID:
                    if (RefundStatusEnum::REFUND_FAILED == $data['refund_status']) {
                        $order_status_name = '退款失败';
                    } elseif (RefundStatusEnum::APPLIED == $data['refund_status']) {
                        $order_status_name = '已申请退款';
                    } else {
                        $order_status_name = '已付款';
                    }
                    break;
                case OrderStatusEnum::COMPLETED:
                    $order_status_name = '已完成';
                    break;
                case OrderStatusEnum::CANCELLED:
                    if (RefundStatusEnum::REFUNDED == $data['refund_status']) {
                        $order_status_name = '已退款';
                    } elseif (RefundStatusEnum::REFUNDING == $data['refund_status']) {
                        $order_status_name = '退款中';
                    } else {
                        $order_status_name = '已取消';
                    }
                    break;
            }
        }
        return $order_status_name;
    }

    /**
     * @Desc 追加订单状态名称字段
     *
     * @param $value
     * @param $data
     *
     * @return string
     */
    protected function getOrderStatusEnnameAttr($value, $data)
    {
        $order_status_enname = '';
        if ($data['is_invalid']) {
            $order_status_enname = 'invalid';
        } elseif (null !== $data['zt']) {
            switch ($data['zt']) {
                case ZtEnum::FAILED:
                    $order_status_enname = 'failed';
                    break;
                case ZtEnum::CANCELLED:
                    $order_status_enname = 'cancelled';
                    break;
                case ZtEnum::WAIT_AUDIT:
                    $order_status_enname = 'wait-audit';
                    break;
                case ZtEnum::AUDITING:
                    $order_status_enname = 'auditing';
                    break;
                case ZtEnum::SUCCESS:
                    $order_status_enname = 'success';
                    switch ($data['order_status']) {
                        case OrderStatusEnum::PAID:
                            if (RefundStatusEnum::REFUND_FAILED == $data['refund_status']) {
                                $order_status_enname = 'refund-failed';
                            } elseif (RefundStatusEnum::APPLIED == $data['refund_status']) {
                                $order_status_enname = 'refund-applied';
                            } elseif (RefundStatusEnum::REFUNDING == $data['refund_status']) {
                                $order_status_enname = 'refunding';
                            } else {
                                $order_status_enname = 'paid';
                            }
                            break;
                        case OrderStatusEnum::COMPLETED:
                            $order_status_enname = 'completed';
                            break;
                        case OrderStatusEnum::CANCELLED:
                            if (RefundStatusEnum::REFUNDED == $data['refund_status']) {
                                $order_status_enname = 'refunded';
                            } else {
                                $order_status_enname = 'cancelled';
                            }
                            break;
                    }
                    break;
                case ZtEnum::CHECKING:
                    $order_status_enname = 'checking';
                    break;
                case ZtEnum::COMPLETED:
                    $order_status_enname = 'completed';
                    break;
            }
        } else {
            switch ($data['order_status']) {
                case OrderStatusEnum::UNPAID:
                    $order_status_enname = 'unpaid';
                    break;
                case OrderStatusEnum::PAID:
                    if (RefundStatusEnum::REFUND_FAILED == $data['refund_status']) {
                        $order_status_enname = 'refund-failed';
                    } elseif (RefundStatusEnum::APPLIED == $data['refund_status']) {
                        $order_status_enname = 'refund-applied';
                    } else {
                        $order_status_enname = 'paid';
                    }
                    break;
                case OrderStatusEnum::COMPLETED:
                    $order_status_enname = 'completed';
                    break;
                case OrderStatusEnum::CANCELLED:
                    if (RefundStatusEnum::REFUNDED == $data['refund_status']) {
                        $order_status_enname = 'refunded';
                    } elseif (RefundStatusEnum::REFUNDING == $data['refund_status']) {
                        $order_status_enname = 'refunding';
                    } else {
                        $order_status_enname = 'cancelled';
                    }
                    break;
            }
        }
        return $order_status_enname;
    }

    /**
     * @Desc 追加退款状态名称字段
     *
     * @param $value
     * @param $data
     *
     * @return string
     */
    protected function getRefundStatusNameAttr($value, $data)
    {
        $refund_status_name = '';
        switch ($data['refund_status']) {
            case RefundStatusEnum::UNAPPLIED:
                $refund_status_name = '未申请';
                break;
            case RefundStatusEnum::APPLIED:
                $refund_status_name = '已申请';
                break;
            case RefundStatusEnum::REFUNDING:
                $refund_status_name = '退款中';
                break;
            case RefundStatusEnum::REFUNDED:
                $refund_status_name = '已退款';
                break;
            case RefundStatusEnum::REFUND_FAILED:
                $refund_status_name = '申请失败';
                break;
        }
        return $refund_status_name;
    }

    /**
     * @Desc 追加支付状态名称字段
     *
     * @param $value
     * @param $data
     *
     * @return false|string
     */
    protected function getPayStatusNameAttr($value, $data)
    {
        $pay_status_name = '';
        switch ($data['pay_status']) {
            case PayStatusEnum::PAID:
                $pay_status_name = '已支付';
                break;
            case PayStatusEnum::UNPAID:
                $pay_status_name = '未支付';
                break;
        }
        return $pay_status_name;
    }

    /**
     * @Desc 获取车辆状态
     *
     * @param $value
     * @param $data
     *
     * @return string
     */
    protected function getCarStateAttr($value, $data)
    {
        $car_state = '';
        switch ($data['order_status']) {
            case OrderStatusEnum::UNPAID:
                $car_state = '待支付';
                break;
            case OrderStatusEnum::PAID:
                $car_state = '待检车';
                break;
            case OrderStatusEnum::COMPLETED:
                $car_state = '检车完成';
                break;
            case OrderStatusEnum::CANCELLED:
                if (RefundStatusEnum::REFUNDED == $data['refund_status']) {
                    $car_state = '已退款';
                } elseif (RefundStatusEnum::REFUNDING == $data['refund_status']) {
                    $car_state = '退款中';
                } else {
                    $car_state = '已取消';
                }
                break;
        }
        return $car_state;
    }

    /**
     * @Desc 追加退款日志字段
     *
     * @param $value
     * @param $data
     *
     * @return array
     */
    protected function getRefundLogAttr($value, $data)
    {
        $refunds = Db::name('refund_log')->field('refund_status, do_time')->where('order_id', '=', $data['order_id'])->order('do_time')->select();
        $refund_log = [];
        foreach ($refunds as $refund) {
            switch ($refund['refund_status']) {
                case RefundStatusEnum::APPLIED:
                    $refund_log['one'] = date('Y-m-d H:i:s', $refund['do_time']);
                    break;
                case RefundStatusEnum::REFUNDING:
                    $refund_log['two'] = date('Y-m-d H:i:s', $refund['do_time']);
                    break;
                case RefundStatusEnum::REFUNDED:
                    $refund_log['three'] = date('Y-m-d H:i:s', $refund['do_time']);
                    break;
                case RefundStatusEnum::REFUND_FAILED:
                    $refund_log['four'] = date('Y-m-d H:i:s', $refund['do_time']);
                    break;
            }
        }
        return $refund_log;
    }

    /**
     * @Desc 获取使用性质
     *
     * @param $value
     * @param $data
     *
     * @return bool|float|mixed|string|null
     */
    protected function getLicenseNatureAttr($value, $data)
    {
        return Db::name('driving_license')->where('id', '=', $data['driving_license_id'])->value('license_nature');
    }

    /**
     * @Desc 获取品牌型号
     *
     * @param $value
     * @param $data
     *
     * @return bool|float|mixed|string|null
     */
    protected function getVehicleBrandAttr($value, $data)
    {
        return Db::name('driving_license')->where('id', '=', $data['driving_license_id'])->value('vehicle_brand');
    }

    /**
     * @Desc 获取发证日期
     *
     * @param $value
     * @param $data
     *
     * @return bool|float|mixed|string|null
     */
    protected function getLicenseGrantDateAttr($value, $data)
    {
        return Db::name('driving_license')->where('id', '=', $data['driving_license_id'])->value('license_grant_date');
    }

    /**
     * @Desc 订单是否评论
     *
     * @param $value
     * @param $data
     *
     * @return int
     */
    protected function getIsCommentAttr($value, $data)
    {
        $user_weixin_id = Token::getUidFromCache();
        $comment = Db::name('comment')->where('user_weixin_id', '=', $user_weixin_id)->where('order_id', '=', $data['order_id'])->find();
        return !empty($comment) ? 1 : 0;
    }

    /**
     * @Desc 根据订单ID查询订单数据
     *
     * @param int $id
     *
     * @return array
     */
    public static function getOrderDetail($id)
    {
        $field = 'company_id, create_time, goods_name, order_id, order_sn, order_status, pay_status, refund_status, subscribe_date, total_amount, driving_license_id, user_weixin_id, user_note, vehicle_name, is_invalid, zt, lsh, mobile, update_time, subscribe_code, sbyy';
        $order = (new self)->field($field)->where('order_id', '=', $id)->find();
        if (!$order) {
            throw new OrderException();
        }
        return $order->append([
            'company_name',
            'user_name',
            'pay_status_name',
            'order_status_name',
            'refund_status_name',
            'license_number',
            'car_state',
            'license_nature',
            'vehicle_brand',
            'license_grant_date',
            'is_comment',
            'telephone',
        ])->hidden(['company_id', 'is_invalid'])->toArray();
    }

    /**
     * @Desc 根据订单ID查询订单数据
     *
     * @param int $id
     *
     * @return array
     */
    public static function getOrderDetailFromCar($id)
    {
        $field = 'company_id, order_id, order_sn, subscribe_date, total_amount, driving_license_id, mobile, create_time, update_time, subscribe_code, sbyy';
        $order = (new self)->field($field)->where('order_id', '=', $id)->find();
        if (!$order) {
            throw new OrderException();
        }
        return $order->append([
            'company_name',
            'user_name',
            'license_number',
            'telephone',
            'remarks',
            'add_time',
            'yuyue_time',
        ])->hidden(['driving_license_id'])->toArray();
    }

    /**
     * @Desc 根据订单ID查询订单数据
     *
     * @param int $id
     *
     * @return array
     */
    public static function getOrderDetailFromCar2()
    {
        $field = 'company_id, order_id, order_sn, subscribe_date, total_amount, driving_license_id, mobile, create_time, update_time, subscribe_code, sbyy';
        $order = (new self)->field($field)->where('zt', '=', 2)->where('subscribe_date', '>', 1602280582)->select();
        if (!$order) {
            throw new OrderException();
        }
        return $order->append([
            'company_name',
            'user_name',
            'license_number',
            'telephone',
            'remarks',
            'add_time',
            'yuyue_time',
        ])->hidden(['driving_license_id'])->toArray();
    }

    /**
     * @Desc 根据订单状态查询订单
     *
     * @param int    $status
     * @param int    $page
     * @param string $searchedTitle
     *
     * @return array
     */
    public static function getOrderList($status, $page = 1, $searchedTitle = '')
    {
        $where = [];
        $company_ids = '';
        $id = Token::getUidFromCache();
        switch ($status) {
            case OrderStatusEnum::PAID:
            case OrderStatusEnum::COMPLETED:
            case OrderStatusEnum::UNPAID:
                $where['order_status'] = $status;
                break;
            case RefundStatusEnum::REFUND_FAILED:
                $where['refund_status'] = RefundStatusEnum::REFUNDED;
                break;
            case OrderStatusEnum::CANCELLED:
                $where['order_status'] = $status;
                $where['refund_status'] = ['<>', RefundStatusEnum::REFUNDED];
                break;
        }
        if (!empty($searchedTitle)) {
            $company_ids = (new Company())->where('company_name', 'like', "%{$searchedTitle}%")->column('id');
        }
        $field = 'create_time, order_id, order_sn, goods_id, goods_name, company_id, order_status, total_amount, subscribe_date, pay_status, refund_status, subscribe_id, vehicle_name, is_invalid, zt, lsh, subscribe_code, driving_license_id';
        // 分页数量
        $listRows = PageEnum::ORDER;
        $list = (new self)->field($field)->where('user_weixin_id', '=', $id)->where($where)->where(static function ($query) use ($company_ids, $searchedTitle) {
            $query->whereOr('company_id', 'in', $company_ids)->whereOr('goods_name', 'like', "%{$searchedTitle}%")->whereOr('order_sn', 'like', "%{$searchedTitle}%");
        })->page($page, $listRows)->order('update_time desc')->select();
        return $list->append(['company_name', 'telephone', 'order_status_name', 'order_status_enname', 'is_comment', 'license_number'])->hidden(['goods_id', 'is_invalid'])->toArray();
    }

    /**
     * @Desc 获取各订单状态的订单数
     * @return array
     */
    public static function getOrderStatusCount()
    {
        $counts = $where = [];
        $where['open_id'] = Token::getOpenidFromCache();
        $order = new self;
        $counts[999] = $order->where($where)->count();
        $orderStatus = OrderStatusEnum::getAllConstants();
        foreach ($orderStatus as $value) {
            $where['order_status'] = $value;
            $counts[$value] = $order->where($where)->count();
        }
        return $counts;
    }

    /**
     * @Desc 新增订单数据
     *
     * @param array $orderData 订单信息
     *
     * @return array
     */
    public static function insertOrder(array $orderData)
    {
        $order = self::create($orderData);
        return [
            'id'          => $order->getAttr('order_id'),
            'create_time' => $order->getData('create_time'),
        ];
    }

    /**
     * @Desc 取消订单
     *
     * @param int $id
     *
     * @return bool
     */
    public static function cancelOrder($id)
    {
        $time = time();
        $data = [
            'order_status' => OrderStatusEnum::CANCELLED,
            'update_time'  => $time,
            'cancel_time'  => $time,
        ];
        $result = self::update($data, ['order_id' => $id]);
        if (!$result) {
            throw new CurdException([
                'message'   => '取消订单失败',
                'errorCode' => 60001,
            ]);
        }
        return true;
    }

    /**
     * @Desc 获取退款订单列表
     *
     * @param int $page
     *
     * @return array
     */
    public static function getRefundList($page = 1)
    {
        $field = 'company_id, create_time, goods_id, goods_name, order_id, order_sn, order_status, pay_status, refund_status, subscribe_date, total_amount, zt, lsh';
        // 分页数量
        $listRows = PageEnum::REFUND;
        $open_id = Token::getOpenidFromCache();
        $list = (new self)->field($field)->where('open_id', '=', $open_id)->where('refund_status', '<>', RefundStatusEnum::UNAPPLIED)->page($page, $listRows)->order('update_time desc')->select();
        return $list->append(['company_name', 'refund_status_name'])->toArray();
    }

    /**
     * @Desc 根据订单ID查询订单数据
     *
     * @param int $id
     *
     * @return array
     */
    public static function getRefundDetail($id)
    {
        $field = 'order_id, order_sn, total_amount, company_id, refund_status, refuse_case, zt, lsh';
        $order = (new self)->field($field)->where('order_id', '=', $id)->find();
        return $order->append(['refund_status_name', 'refund_log', 'telephone'])->hidden(['order_id', 'company_id'])->toArray();
    }

    /**
     * @Desc 更新退款订单
     *
     * @param $id
     *
     * @return bool
     */
    public static function updateRefundStatus($id)
    {
        Db::startTrans();
        try {
            if (!$order = self::get($id)) {
                throw new OrderException();
            }
            $time = time();
            $uploadData = [
                // 'reback_case'   => $reback_case,
                'refund_status' => RefundStatusEnum::APPLIED,
                'update_time'   => $time,
            ];
            if (!self::update($uploadData, ['order_id' => $id])) {
                throw new CurdException();
            }
            $createData = [
                'order_id'      => $id,
                'refund_status' => RefundStatusEnum::APPLIED,
                'do_time'       => $time,
            ];
            if (!RefundLog::create($createData)) {
                throw new CurdException();
            }
            // 生成积分数据
            $memberData = [
                'user_weixin_id' => $order['user_weixin_id'],
                'number'         => $order['total_amount'],
                'type'           => MemberLogEnum::REDUCE,
                'get_from'       => MemberLogEnum::FROM_REBACK,
                'create_time'    => $time,
                'update_time'    => $time,
            ];
            // 添加积分记录
            MemberLog::insertMemberData($memberData);
            // 增加积分
            (new UserWeixin())->where('id', '=', $order['user_weixin_id'])->setDec('member', $order['total_amount']);
            Db::commit();
            return true;
        } catch (Exception $e) {
            Db::rollback();
            Log::error($e);
            throw $e;
        }
    }

    /**
     * @Desc 更新订单状态
     *
     * @param $param
     *
     * @return SuccessMessage
     */
    public static function updateOrderZt($param)
    {
        $data = ['zt' => $param['zt']];
        if(array_key_exists('sbyy', $param)){
            $data['sbyy'] = $param['sbyy'];
        }
        self::update($data, ['order_id' => $param['order_id']]);
        return new SuccessMessage();
    }

    /**
     * @Desc 更新订单状态
     *
     * @param $orderData
     * @param $order_sn
     *
     * @return SuccessMessage
     */
    public static function updateOrder($orderData, $order_sn)
    {
        self::update($orderData, ['order_sn' => $order_sn]);
        return new SuccessMessage();
    }
}